﻿Imports BLL
Public Class UsuarioCAD
    Inherits System.Web.UI.Page
    Dim objbll As New UsuarioBLL
    Dim cod As Integer = 0
#Region "Eventos"
#Region "Botão Gravar"
    Protected Sub BGravar_Click(sender As Object, e As EventArgs) Handles BGravar.Click
        Try
            If (Val(TCodigo.Text) > 0) Then
                If (TSenha.Text.Trim <> "") Then
                    objbll = New UsuarioBLL(Val(TCodigo.Text), TLogin.Text.Trim, TSenha.Text.Trim, Char.Parse(rbstatus.SelectedValue))
                Else
                    objbll = New UsuarioBLL(Val(TCodigo.Text))
                    objbll.login = TLogin.Text.Trim
                    objbll.status = Char.Parse(rbstatus.SelectedValue)
                End If
            Else
                objbll = New UsuarioBLL(Val(TCodigo.Text), TLogin.Text.Trim, TSenha.Text.Trim, Char.Parse(rbstatus.SelectedValue))
            End If
            If (objbll.InserirAlterar(Session("usu_nome"))) Then
                BGravar.Enabled = False
                LMSG.Text = "Gravado com Sucesso!"
                LMSG.Visible = True
            End If
        Catch ex As Exception
            LMSG.ForeColor = Drawing.Color.Red
            LMSG.Text = ex.Message
            LMSG.Visible = True
        End Try
    End Sub
#End Region

#Region "Load"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cod = 0
        If Not IsPostBack() Then
            If Not IsNothing(Request("id")) Then
                cod = Val(Request("id"))
                BGravar.Text = "Alterar"
                carrega()
            End If
        End If
    End Sub
#End Region
#End Region

#Region "Métodos"
    Public Sub carrega()
        objbll = New UsuarioBLL(Val(cod))
        TCodigo.Text = objbll.Codigo
        TLogin.Text = objbll.login
        TSenha.Text = objbll.senha
        rbstatus.SelectedValue = objbll.status
    End Sub
#End Region


End Class